﻿using Windows.ApplicationModel.Search;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;

// The Grouped Items Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234231

namespace MetroContractSample
{
  /// <summary>
  /// A page that displays a grouped collection of items.
  /// </summary>
  public sealed partial class GroupedItemsPage : MetroContractSample.Common.LayoutAwarePage
  {
    public GroupedItemsPage()
    {
      this.InitializeComponent();
    }

    /// <summary>
    /// Invoked when this page is about to be displayed in a Frame.
    /// </summary>
    /// <param name="e">Event data that describes how this page was reached.  The Parameter
    /// property provides the grouped collection of items to be displayed.</param>
    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
      this.DefaultViewModel["Groups"] = App.DataSource.ItemGroups;
    }


    /// <summary>
    /// Invoked when a group header is clicked.
    /// </summary>
    /// <param name="sender">The Button used as a group header for the selected group.</param>
    /// <param name="e">Event data that describes how the click was initiated.</param>
    void Header_Click(object sender, RoutedEventArgs e)
    {
      // Determine what group the Button instance represents
      var group = (sender as FrameworkElement).DataContext;

      // Navigate to the appropriate destination page, configuring the new page
      // by passing required information as a navigation parameter
      this.Frame.Navigate(typeof(GroupDetailPage), group);
    }

    /// <summary>
    /// Invoked when an item within a group is clicked.
    /// </summary>
    /// <param name="sender">The GridView (or ListView when the application is snapped)
    /// displaying the item clicked.</param>
    /// <param name="e">Event data that describes the item clicked.</param>
    void ItemView_ItemClick(object sender, ItemClickEventArgs e)
    {
      // Navigate to the appropriate destination page, configuring the new page
      // by passing required information as a navigation parameter
      this.Frame.Navigate(typeof(ItemDetailPage), e.ClickedItem);
    }




    // Quickstart: Adding search to a Metro style app 
    // http://msdn.microsoft.com/en-us/library/windows/apps/hh868180.aspx

    private void SearchButton_Click_1(object sender, RoutedEventArgs e)
    {
      SearchPane.GetForCurrentView().Show();
    }

  }
}
